<template>
  <el-table
      :data="tableData"
      style="width: 100%"
      :border="border"
  >
    <component
        v-for="(item,index) in columnOption"
        :key="index"
        v-bind="item"
        :is="item.type || 'textColumn'"
        :patchEvent="patchEvent"
    >
    </component>
  </el-table>
</template>

<script>
// 加载所有./ColumnComponent下组件
let compos = {}
const modules = require.context('./ColumnComponent', false, /.vue$/)
for (let item of modules.keys()) {
  compos[item.match(/.*\.\/(.*).vue$/)[1]] = modules(item).default
}

export default {
  name: "GeneralTable",
  props: {
    // 表格数据
    tableData: {
      type: Array,
      default() {
        return []
      }
    },
    // 是否带边框
    border: {
      type: Boolean,
      default() {
        return true
      }
    },
    // 表格列配置
    columnOption: {
      type: Array,
      default() {
        return [];
      }
    },
  },
  data() {
    return {
    }
  },
  components: {
    ...compos
  },
  methods: {
    // 分发事件,将子组件的事件传递到父组件
    patchEvent(event,args) {
      this.$emit(event, args)
    },
  },
  mounted() {
  }
}
</script>

<style scoped>
.el-table {
  margin-top: 10px;
}
</style>
